//
//  HWContactUsViewController.m
//  HWPromoteProjectAPP
//
//  Created by 陈道斌 on 2020/3/9.
//  Copyright © 2020 陈道斌. All rights reserved.
//

#import "HWContactUsViewController.h"
#import "HWContactUsViewCell.h"



@interface HWContactUsViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(strong,nonatomic) UITableView *mainTabelView;
@property(strong,nonatomic) UIView *hederView;
@property(strong,nonatomic) UIImageView *icoimageView;

@property(strong,nonatomic) UIImageView *erweimaIamgeView;
@property(strong,nonatomic) UILabel *biatimianshuLabel;
@property(strong,nonatomic) NSDictionary *dataDic;





@end

@implementation HWContactUsViewController
- (UITableView *)mainTabelView {
    
    if (_mainTabelView == nil) {
        _mainTabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
        _mainTabelView.delegate = self;
        _mainTabelView.dataSource = self;
        _mainTabelView.backgroundColor = beijingyanSe;
        //  _mainTabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        
        
    }
    
    return _mainTabelView;
    
    
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupshuxing];
    
    [self setupUI];
    // 发送网请求
    [self sendNetworkRequest];
    
    
}


- (void)setupshuxing {
    
    
    self.navigationItem.title = @"联系我们";
    self.view.backgroundColor = beijingyanSe;
    
    
    
    
    
}

// 设置UI
- (void)setupUI {
    
    [self.view addSubview:self.mainTabelView];
    
    [self addheaderView];
    
    
}

- (void)addheaderView {
    
    
    UIView *headeView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 222)];
    
    self.icoimageView = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-82)/2, (222 - 82)/2, 82, 82)];
    self.icoimageView.backgroundColor = [UIColor whiteColor];
    self.icoimageView.layer.cornerRadius = 8;
    self.icoimageView.layer.masksToBounds = YES;
    [headeView addSubview:self.icoimageView];
    
    
    self.mainTabelView.tableHeaderView = headeView;
    
    
    UIView *footeView =  [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];
    
    self.erweimaIamgeView = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-120)/2, 50, 120, 120)];
    self.erweimaIamgeView.backgroundColor = [UIColor whiteColor];
    [footeView addSubview:self.erweimaIamgeView];
    
    UILabel *zongrenLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 50+120+10, SCREEN_WIDTH, 20)];
    //       zongrenLabel.layer.cornerRadius = 60;
    //       zongrenLabel.layer.masksToBounds = YES;
    zongrenLabel.text = [NSString stringWithFormat:@"%@",@"微信公众号"];
    zongrenLabel.font = [UIFont systemFontOfSize:14];
    zongrenLabel.numberOfLines = 2 ;
    zongrenLabel.textAlignment = NSTextAlignmentCenter;
    
    zongrenLabel.textColor = RGB(68, 68, 68);
    [footeView  addSubview:zongrenLabel];
    
    
    
    
    
    
    
    self.mainTabelView.tableFooterView =footeView;
    
    
    
    
    
    
    
    
    
    
    
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return  3;
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    //  UITableViewCell *cell =
    
    static NSString *cellID = @"cellID";
    
    HWContactUsViewCell *cell =  [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (!cell) {
        cell =  [[NSBundle mainBundle]loadNibNamed:@"HWContactUsViewCell" owner:nil options:nil].firstObject;
        
    }
    if (indexPath.row == 0 ) {
        cell.zuobianLabel.text = @"工作时间";
        cell.rightLabel.text = self.dataDic[@"time"];
        
        
        
        
    } else if (indexPath.row == 1) {
        
        
        cell.zuobianLabel.text = @"客服电话";
        cell.rightLabel.text = self.dataDic[@"phone"];
        
        
        
        
        
    }else if ( indexPath.row == 2) {
        
        
        cell.zuobianLabel.text = @"客服 QQ";
        cell.rightLabel.text = self.dataDic[@"qq"];
    }
    
    
    
    return  cell;
    
    
    
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return  44;
    
    
}



- (void)tableView:(UITableView *)tableView willDisplayCell:(nonnull UITableViewCell *)cell forRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    //设置separatorInset(iOS7之后)
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}





// 发送网络请求
- (void)sendNetworkRequest {
    
    
    
    
    NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
    NSString *uid =  [HWLocallyStoredData getLoginUserID];
    NSString *signStr = [NSString stringWithFormat:@"%@%@%@",uid,tStr,@"adesxloksy13s98adv"];
    NSString  *signStrMd5  =   [WMUtil md5HexDigest:signStr];
    
    
    
    
    NSDictionary *parametes = @{      @"ios" : @"1",
                                      @"ct" : @"app",
                                      @"ac" : @"kefu",
                                      
    };
    
    
    [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
        
        
        
        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
        if ([codeStr intValue] == 1) {
            
            NSLog(@"%@",response);
            NSLog(@"%@",response);
            
            
            self.dataDic = response[@"data"];
            
            NSString *icoStr =  self.dataDic[@"icon"];
            NSString *gzh = self.dataDic[@"gzh"];
            
            [self.icoimageView sd_setImageWithURL:[NSURL URLWithString:icoStr] placeholderImage:nil];
            [self.erweimaIamgeView sd_setImageWithURL:[NSURL URLWithString:gzh] placeholderImage:nil];
            
            
            
            [self.mainTabelView reloadData];
            
            
            
            
            
            
        } else {
            
            [MBProgressHUD showError:response[@"message"]];
            
            
            
        }
        
        
        
    } failure:^(NSString *error) {
        // [SVProgressHUD dismiss];
        
        [MBProgressHUD showSuccess:@"登录失败"];
        [MBProgressHUD hideHUD];
        
        
        
        
    }];
    
    
}









@end
